/*
 * Licensed to Elasticsearch B.V. under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch B.V. licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

using System;
using System.Runtime.Serialization;

namespace Nest
{
	[ReadAs(typeof(Phases))]
	public interface IPhases
	{
		[DataMember(Name = "cold")]
		IPhase Cold { get; set; }

		[DataMember(Name = "delete")]
		IPhase Delete { get; set; }

		[DataMember(Name = "hot")]
		IPhase Hot { get; set; }

		[DataMember(Name = "warm")]
		IPhase Warm { get; set; }

		[DataMember(Name = "frozen")]
		IPhase Frozen { get; set; }
	}

	public class Phases : IPhases
	{
		public IPhase Cold { get; set; }
		public IPhase Delete { get; set; }
		public IPhase Hot { get; set; }
		public IPhase Warm { get; set; }
		public IPhase Frozen { get; set; }
	}

	public class PhasesDescriptor : DescriptorBase<PhasesDescriptor, IPhases>, IPhases
	{
		IPhase IPhases.Cold { get; set; }
		IPhase IPhases.Delete { get; set; }
		IPhase IPhases.Hot { get; set; }
		IPhase IPhases.Warm { get; set; }
		IPhase IPhases.Frozen { get; set; }

		public PhasesDescriptor Warm(Func<PhaseDescriptor, IPhase> selector) =>
			Assign(selector, (a, v) => a.Warm = v?.InvokeOrDefault(new PhaseDescriptor()));

		public PhasesDescriptor Hot(Func<PhaseDescriptor, IPhase> selector) =>
			Assign(selector, (a, v) => a.Hot = v?.InvokeOrDefault(new PhaseDescriptor()));

		public PhasesDescriptor Cold(Func<PhaseDescriptor, IPhase> selector) =>
			Assign(selector, (a, v) => a.Cold = v?.InvokeOrDefault(new PhaseDescriptor()));

		public PhasesDescriptor Delete(Func<PhaseDescriptor, IPhase> selector) =>
			Assign(selector, (a, v) => a.Delete = v?.InvokeOrDefault(new PhaseDescriptor()));

		public PhasesDescriptor Frozen(Func<PhaseDescriptor, IPhase> selector) =>
			Assign(selector, (a, v) => a.Frozen = v?.InvokeOrDefault(new PhaseDescriptor()));
	}
}
